package com.devilvan.reviewWordCount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordCountReducer extends Reducer<Text, LongWritable,Text,LongWritable> {
    private LongWritable resultValue;

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        resultValue = new LongWritable();
    }

    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        long sum = 0;
        for (LongWritable value : values) {
            sum += value.get();
        }
        resultValue.set(sum);
        context.write(key,resultValue);
    }
}
